<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>软件技术一班23003019陈建宇待办列表</title>
    <style>
        body{
            margin: 0;
            padding: 0;
            height: 100%;
            background-color: gainsboro;
        }
        header{
            text-align: center;
            padding: 5px;
            background: url(4.jpg ) no-repeat;
            background-size: cover;
        }
        .container {
            width: 100%;
            margin: 0 auto;
            padding: 20px;
            background-color: white;
            background-color: gainsboro;
        }
        ul {
            list-style-type: none;
            padding: 0;
        }
        li {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
            padding: 10px;
            border: 1px solid #ddd;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 3px 10px 4px #EEF0B4;
        }
        .completed {
            text-decoration: line-through;
        }
        input[type="text"]{
            width: 90%;
            font-size: 18px;
border-radius: 10px;
padding: 10px;
margin-bottom: 10px;
        }
        input[type="button"]{
            width: 80px;
            margin-left: 15px;
            font-size: 20px;
            border-radius: 10px;
            cursor: pointer;
            border: none;
            
        }
        input[type="button"]:hover{
            background-color: yellowgreen;
        }
        .del{
            margin-right: 10px;
        }
    </style>
</head>
<body>
    <header>
        <h1>待办列表</h1>
    </header>
    <div class="container">
        <input type="text" id="task" placeholder="添加新任务">
        <input type="button" value="添加" onclick="addTask()">
        <ul id="taskList">
            
        </ul>
        <script>
      function addTask() {
            const taskInput = document.getElementById('task');
            const taskText = taskInput.value.trim();
            if (taskText === '') return;

            const taskList = document.getElementById('taskList');
            const listItem = document.createElement('li');
            listItem.innerHTML = `
                <span>${taskText}</span>
                <input type="checkbox" onchange="toggleTaskComplete(this)">
                <button onclick="deleteTask(this)" class="del">删除</button>
            `;
            taskList.appendChild(listItem);
            taskInput.value = '';//这步是关键
        }
        function deleteTask(button) {
            const listItem = button.parentElement;
            listItem.remove();
        }
        function toggleTaskComplete(checkbox) {
            const taskText = checkbox.previousElementSibling;
            if (checkbox.checked) {
                taskText.classList.add('completed');
            } else {
                taskText.classList.remove('completed');
            }
        }
        </script>
</body>
</html>